package com.dg11185.nearshop.baidumap;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.nearshop.R;

/**
 * 公交、驾车、步行三个list共用的adapter，如果使用SimpleAdapter的话会不断的new对象
 * @author：Daibo    
 * @time：2014-5-11 下午3:07:54
 */
public class RouteListAdapter extends BaseAdapter {

    private final LayoutInflater inflater;
    
    private List<RouteData> routes;
    
    public RouteListAdapter(Context context){
        super();
        inflater = LayoutInflater.from(context);
        routes = new ArrayList<RouteListAdapter.RouteData>();
    }
    
    public void setRouteList(List<RouteData> routeList) {
        this.routes = routeList;
    }
    
    @Override
    public int getCount() {
        return routes.size();
    }

    @Override
    public Object getItem(int position) {
        return routes.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.map_shop_route_list_item, parent, false);
            holder.numTxt = (TextView) convertView.findViewById(R.id.route_number);
            holder.conTxt = (TextView) convertView.findViewById(R.id.route_content);
            holder.disTxt = (TextView) convertView.findViewById(R.id.route_distance);
            holder.timetxt= (TextView) convertView.findViewById(R.id.route_time);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        
        holder.numTxt.setText(routes.get(position).numerical);
        holder.conTxt.setText(routes.get(position).content);
        holder.disTxt.setText(routes.get(position).distance);
        holder.timetxt.setText(routes.get(position).time);
        return convertView;
    }

    class ViewHolder{
        private TextView numTxt;
        
        private TextView conTxt;
        
        private TextView disTxt;
        
        private TextView timetxt;
    }
    /**
     * {@link RouteListAdapter} 显示需要的数据对象
     * @author：Daibo    
     * @time：2014-5-8 上午9:19:28
     */
    public static class RouteData {
        public String numerical = "";

        public String content = "";

        public String distance = "";

        public String time = "";
    }
}
